import { buildLocalIconNames } from './assets/script/buildIcons'

if (process.env.VITE_ENV && !process.env.VITE_API_BASE_URL) {
    throw new Error('请先于 .env.production 文件内，配置生产环境的 VITE_API_BASE_URL')
}

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
    runtimeConfig: {
        public: {
            env: process.env.VITE_ENV,
            apiBaseUrl: process.env.VITE_API_BASE_URL,
        },
    },
    typescript: {
        shim: false,
    },
    modules: ['@vueuse/nuxt', '@unocss/nuxt', '@element-plus/nuxt', '@pinia/nuxt', '@pinia-plugin-persistedstate/nuxt', 'nuxt-icons'],
    imports: {
        dirs: ['stores'],
    },
    hooks: {
        'build:before': () => {
            buildLocalIconNames()
        },
    },
    vite: {
        resolve: {
            alias: {
                'vue-i18n': process.env.VITE_ENV == 'production' ? 'vue-i18n/dist/vue-i18n.cjs.prod.js' : 'vue-i18n/dist/vue-i18n.cjs.js',
            },
        },
    },
    // 直接加载el的css以供随时使用 --el 开头的css类
    css: [
        'element-plus/dist/index.css',
        'element-plus/theme-chalk/display.css',
        '~/assets/scss/index.scss',
        '~/assets/newsite/189c9b44f6118b16.css',
        '~/assets/newsite/mainsite.css',
        'font-awesome/css/font-awesome.min.css',
    ],

    vueuse: {
        ssrHandlers: true,
    },
    unocss: {
        uno: true,
        attributify: true,
        icons: {
            scale: 1.2,
        },
    },
    elementPlus: {
        icon: false,
    },
    pinia: {
        disableVuex: true,
    },
    piniaPersistedstate: {
        cookieOptions: {
            sameSite: 'strict',
            maxAge: 2592000,
        },
    },
    // https://github.com/unocss/unocss/issues/2113
    sourcemap: {
        server: true,
        client: false,
    },
    app: {
        head: {
            title: '超算智能体',
            charset: 'utf-8',
            viewport: 'width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=0',
            meta: [
                { charset: 'utf-8' },
                { name: 'viewport', content: 'width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=0' },
                { name: 'description', content: '超算智能体-打响政企智能化的第一枪！智能体MaaS平台，为政企客户一键部署专属智能体。零代码、零训练、零部署，支持知识库。' },
                { name: 'keywords', content: '智能化转型、AI解决方案服务商。超算智能体（SuperAI），智能体、AI Agent、Agent、MaaS、智能体解决方案、零代码智能体、零训练智能体、大模型训练、AI定制' },
            ]
        },
    },
    build: {
        transpile: ['@popperjs'],
    }
})
